package com.su.dolphin.utils;

import android.annotation.SuppressLint;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 * TimeUtils
 * 
 * @author <a href="http://www.trinea.cn" target="_blank">Trinea</a> 2013-8-24
 */
@SuppressLint ("SimpleDateFormat")
public class TimeUtil
{
    
    /**
     * long time to string
     * 
     * @param timeInMillis
     * @param dateFormat
     * @return
     */
    public static String getTime(long timeInMillis, SimpleDateFormat dateFormat) {
        return dateFormat.format(new Date(timeInMillis));
    }
    
    /**
     * long time to string, format is {@link #DEFAULT_DATE_FORMAT}
     * 
     * @param timeInMillis
     * @return
     */
    public static String getTime(long timeInMillis) {
        return getTime(timeInMillis, yyyy_MM_ddHHmmss.get());
    }
    
    /**
     * get current time in milliseconds
     * 
     * @return
     */
    public static long getCurrentTimeInLong() {
        return System.currentTimeMillis();
    }
    
    /**
     * get current time in milliseconds, format is {@link #DEFAULT_DATE_FORMAT}
     * 
     * @return
     */
    public static String getCurrentTimeInString() {
        return getTime(getCurrentTimeInLong());
    }
    
    /**
     * get current time in milliseconds
     * 
     * @return
     */
    public static String getCurrentTimeInString(SimpleDateFormat dateFormat) {
        return getTime(getCurrentTimeInLong(), dateFormat);
    }
    
    //==================================format define;
    /**
     * 2016-06-12 19:30:22
     */
    public static final ThreadLocal<java.text.SimpleDateFormat> yyyy_MM_ddHHmmss = new ThreadLocal<java.text.SimpleDateFormat>()
    {
        protected SimpleDateFormat initialValue() {
            return new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
        }
    };
    /**
     * 20160612193022
     */
    public static final ThreadLocal<java.text.SimpleDateFormat> yyyyMMddHHmmss = new ThreadLocal<java.text.SimpleDateFormat>()
    {
        protected SimpleDateFormat initialValue() {
            return new java.text.SimpleDateFormat("yyyyMMddHHmmss", Locale.CHINA);
        }
    };
    
    /**
     * 2016-06-12 19:30
     */
    public static final ThreadLocal<java.text.SimpleDateFormat> yyyy_MM_ddHHmm = new ThreadLocal<java.text.SimpleDateFormat>()
    {
        protected SimpleDateFormat initialValue() {
            return new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.CHINA);
        }
    };
    /*
     * 20150506
     */
    public static final ThreadLocal<java.text.SimpleDateFormat> yyyyMMdd = new ThreadLocal<java.text.SimpleDateFormat>()
    {
        protected SimpleDateFormat initialValue() {
            return new java.text.SimpleDateFormat("yyyyMMdd", Locale.CHINA);
        }
    };
    /*
     * 2016-06-04
     */
    public static final ThreadLocal<java.text.SimpleDateFormat> yyyy_MM_dd = new ThreadLocal<java.text.SimpleDateFormat>()
    {
        protected SimpleDateFormat initialValue() {
            return new java.text.SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
        }
    };
    /**
     * 16-06-04
     */
    public static final ThreadLocal<java.text.SimpleDateFormat> yyMMdd = new ThreadLocal<java.text.SimpleDateFormat>()
    {
        protected SimpleDateFormat initialValue() {
            return new java.text.SimpleDateFormat("yy-MM-dd", Locale.CHINA);
        }
    };
    /**
     * 16:06
     */
    public static final ThreadLocal<java.text.SimpleDateFormat> HHmm = new ThreadLocal<java.text.SimpleDateFormat>()
    {
        protected SimpleDateFormat initialValue() {
            return new java.text.SimpleDateFormat("HH:mm", Locale.CHINA);
        }
    };
    
}
